﻿// Copyright (c) Microsoft Corporation.  All rights reserved. 
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WiE.Model;

namespace WiE
{
    /// <summary>
    /// This form is used to collect login and membership (if new member) information.
    /// </summary>
    public partial class FormJoinCommunity : Form
    {
        private bool m_bCancel = false;
        private bool m_bExistingMember = false;
        private bool m_bAutoSignIn = true;
        private string m_strFirstName = "";
        private string m_strLastName = "";
        private string m_strUserName = "";
        private string m_strUserPassword = "";
        private string m_strPhoneNumber = "";
        private string m_strEmail = "";

        /// <summary>
        /// Constructor
        /// </summary>
        public FormJoinCommunity()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Returns true if the user indicated that he was an existing user.
        /// </summary>
        public bool ExistingMember
        {
            set { m_bExistingMember = value; }
            get { return m_bExistingMember; }
        }

        /// <summary>
        /// Returns true if the user selected to automatically sign in.
        /// </summary>
        public bool AutoSignIn
        {
            set { m_bAutoSignIn = value; }
            get { return m_bAutoSignIn; }
        }

        /// <summary>
        /// Returns true if the user chose to cancel out of "joining".
        /// </summary>
        public bool UserSelectedCancel
        {
            get { return m_bCancel; }
        }

        /// <summary>
        /// The first name of the member
        /// </summary>
        public string FirstName
        {
            set { m_strFirstName = value; }
            get { return m_strFirstName; }
        }

        /// <summary>
        /// The last name of the member
        /// </summary>
        public string LastName
        {
            set { m_strLastName = value; }
            get { return m_strLastName; }
        }

        /// <summary>
        /// The e-mail address associated with the member
        /// </summary>
        public string Email
        {
            set { m_strEmail = value; }
            get { return m_strEmail; }
        }

        /// <summary>
        /// The PhoneNumber for the member
        /// </summary>
        public string PhoneNumber
        {
            set { m_strPhoneNumber = value; }
            get { return m_strPhoneNumber; }
        }

        /// <summary>
        /// The UserName for the member
        /// </summary>
        public string UserName
        {
            set { m_strUserName = value; }
            get { return m_strUserName; }
        }

        /// <summary>
        /// The Password for the member (someday we may not want to send this back and forth).
        /// </summary>
        public string Password
        {
            set { m_strUserPassword = value; }
            get { return m_strUserPassword; }
        }


        private void m_checkBoxExistingMember_Click(object sender, EventArgs e)
        {
            // User has selected / unselected the I'm already a member, which is used to decide if
            // the additional data capture fields should be enabled / disabled.
            m_panelJoinControls.Enabled = !(m_checkBoxExistingMember.Checked);

            //m_textBoxEmail.Enabled = !(m_checkBoxExistingMember.Checked);
            //m_textBoxFirstName.Enabled = !(m_checkBoxExistingMember.Checked);
            //m_textBoxLastName.Enabled = !(m_checkBoxExistingMember.Checked);
            //m_textBoxPhone.Enabled = !(m_checkBoxExistingMember.Checked);
        }

        private void PopulateProperties()
        {
            m_bExistingMember = m_checkBoxExistingMember.Checked;
            m_bAutoSignIn = m_checkBoxAutoLogin.Checked;
            m_strFirstName = m_textBoxFirstName.Text;
            m_strLastName = m_textBoxLastName.Text;
            m_strUserName = m_textBoxUserName.Text;
            m_strUserPassword = m_textBoxPassword.Text;
            m_strEmail = m_textBoxEmail.Text;
            m_strPhoneNumber = m_textBoxPhone.Text;
        }

        private void m_menuItemJoin_Click(object sender, EventArgs e)
        {
            PopulateProperties();
            m_bCancel = false;
            DialogResult = DialogResult.OK;
            Close();
        }

        private void m_menuItemCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            m_bCancel = true;
            Close();
        }

        private void FormJoinCommunity_Load(object sender, EventArgs e)
        {
            // Populate the fields with any values that were set
            m_checkBoxExistingMember.Checked = ExistingMember;
            m_checkBoxAutoLogin.Checked = AutoSignIn;
            m_textBoxEmail.Text = Email;
            m_textBoxFirstName.Text = FirstName;
            m_textBoxLastName.Text = LastName;
            m_textBoxUserName.Text = UserName;
            m_textBoxPassword.Text = Password;
            m_panelJoinControls.Enabled = !(ExistingMember);

            // Start at the username box
            m_textBoxUserName.Focus();
        }
    }
}